package 力扣日常刷题.木22一月.第04天0111;

/**
 * @author 帅小伙
 * @date 2022/1/11
 * @description
 */
public class Demo08回溯中等统计按位或能得到最大值的子集数目 {


    int max = 0;
    int ans = 0;

    public int countMaxOrSubsets(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            max |= nums[i];
        }
        dfs(0,nums,0);
        return ans;
    }

    void dfs(int index, int[] nums, int target) {
        if (index == nums.length) {
            if (target == max) {
                ans++;
            }
            return;
        }
        int t = target|nums[index];
        dfs(index+1,nums,t);
        t = target;
        dfs(index+1,nums,t);
    }


}
